﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Framework.Verifications;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Protocol.equipment;
using Pixysoft.Weblications.Sango.Protocol;

namespace Pixysoft.Weblications.Sango.Command.officer
{
    partial class SangoOfficerHandler
    {
        public officer_unequip officer_unequip(string officerprimarycode, long eqmtypecode)
        {
            string userCode = SangoManager.Authentication();

            officer_unequip response = ReflectionManager.CreatePojo<officer_unequip>();
            response.Succeed = false;

            if (!Verification.Verifies(officerprimarycode).IsNotNullOrEmpty().Result())
            {
                response.Message = "丢失参数";
                return response;
            }

            Entities.Usr_Officer officer = OfficerDao.getUserOfficer(userCode, officerprimarycode);

            Entities.Usr_Equipment onEqm = EquipmentDao.tryGetOfficerEqm(userCode, officerprimarycode, eqmtypecode);

            if (onEqm == null)
            {
                response.Succeed = false;
                return response;
            }

            Entities.Usr_Property property = UsrPropertyDao.getProperty(userCode);
            if (property.Usedrepositorycount >= property.Repositorycount)
            {
                response.Message = "仓库位不足，无法卸下";
                return response;
            }

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;
            command.Begin(delegate()
            {
                if (OfficerDao.eqmOff(officer, onEqm, property))
                {
                    command.Update(officer);
                }

                command.Update(onEqm);
                command.Update(property);
                command.Commit();
            });

            response.property = UsrProfileFacade.ToProperty(property);
            response.equipment = EquipmentFacade.ToEquipment(onEqm, EquipmentDao.getUserEqmExtras(userCode, onEqm.Primarycode));
            response.Succeed = true;
            return response;
        }


    }
    public interface officer_unequip : ISangoResponse
    {
        usr_equipment equipment { get;set;}

        player_property property { get;set;}
    }
}
